import torch.nn.functional as F
import torch

def bce_loss(inputs, targets):
    """
    inputs: (torch.float32)  shape (N, C, H, W)  (16, 2, 160, 160)
    targets: (torch.float32) shape (N, H, W), value {0,1,...,C-1}  (16, 160, 160)
    """
    targets = torch.unsqueeze(targets, dim=1)
    targets = torch.zeros_like(inputs).scatter_(dim=1, index=targets.type(torch.int64), value=1.0)
    loss = F.binary_cross_entropy_with_logits(inputs, targets)
    return loss